package com.pj.project.sys_swiper;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.pj.current.satoken.AuthConst;
import com.pj.project4sp.SP;
import com.pj.utils.sg.AjaxJson;
import com.pj.utils.sg.SoMap;

import cn.dev33.satoken.stp.StpUtil;

/**
 * Controller: 轮播图片表
 * @author kong 
 */
@RestController
@RequestMapping("/SysSwiper/")
public class SysSwiperController {


	/** 底层 Mapper 对象 */
	@Autowired
	SysSwiperMapper sysSwiperMapper;

	// 增  
	@RequestMapping("add")
    AjaxJson add(SysSwiper s){
		StpUtil.checkPermission("sys-swiper");	// 鉴权
		s.setSort(System.currentTimeMillis());		// 新增加的排序值设定为当前时间 
		int line = sysSwiperMapper.add(s);
		return AjaxJson.getByLine(line);
	}

	// 删  
	@RequestMapping("delete")
    AjaxJson delete(String id){
		StpUtil.checkPermission("sys-swiper");	// 鉴权
		int line = sysSwiperMapper.delete(id);
		return AjaxJson.getByLine(line);
	}


	/** 删 - 根据id列表 */  
	@RequestMapping("deleteByIds")
	AjaxJson deleteByIds(){
		StpUtil.checkPermission("sys-swiper");	// 鉴权
		List<Long> ids = SoMap.getRequestSoMap().getListByComma("ids", long.class); 
		int line = SP.publicMapper.deleteByIds("sys_swiper", ids);
		return AjaxJson.getByLine(line);
	}
	
	// 改  
	@RequestMapping("update")
    AjaxJson update(SysSwiper s){
		StpUtil.checkPermission("sys-swiper");	// 鉴权
		int line = sysSwiperMapper.update(s);
		return AjaxJson.getByLine(line);
	}

	// 查  
	@RequestMapping("getById")
    AjaxJson getById(String id){
		StpUtil.checkPermission("sys-swiper");	// 鉴权
		SysSwiper s = sysSwiperMapper.getById(id);
		return AjaxJson.getSuccessData(s);
	}

	// 查 - 集合（参数为null或0时默认忽略此条件）  
	@RequestMapping("getList")
    AjaxJson getList() {
		StpUtil.checkPermission("sys-swiper");	// 鉴权
		SoMap so = SoMap.getRequestSoMap();
		List<SysSwiper> list = sysSwiperMapper.getList(so.startPage());
		return AjaxJson.getPageData(so.getDataCount(), list);
	}
	
	
	// 更改一个排序值 
	@RequestMapping("updateSort")
	public AjaxJson setTop(long id, long sort, HttpServletRequest request){
		StpUtil.checkPermission(AuthConst.r1);	// 鉴权
		int line = SP.publicMapper.updateColumnById("sys_swiper", "sort", sort, id);
		return AjaxJson.getByLine(line);
	}
	
	

	// 拉取首页轮播图
	@RequestMapping("getListByIndex")
    AjaxJson getListByIndex() {
		SoMap so = SoMap.getRequestSoMap();
		so.setDefaultValue("type", 1);
//		so.put("type", 1);		// 条件限定必须为：1
		so.put("status", 1);	// 条件限定必须为：1  
		List<SysSwiper> list = sysSwiperMapper.getList(so);
		return AjaxJson.getSuccessData(list);
	}
	

	// 指定轮播图增加一次点击
	@RequestMapping("addClick")
    AjaxJson addClick(long id) {
		int line = SP.publicMapper.columnAdd("sys_swiper", "click_count", 1, id);
		return AjaxJson.getByLine(line);
	}

	
	
	
}
